// pages/cash/cash.js
const apiurl = require('../../config').apiurl;
import { Pulibc } from '../../models/public.js'
const pulibc = new Pulibc();
Page({
  showCashDetals(){
    pulibc.navigateUrl('../cash-details/cash-details')
  },
  /**
   * 页面的初始数据
   */
  data: {
    totalMoney:0,
    info:{},
    cashInfo:{}
  },
  // 提现页面
  getCashInfo(){
    let url = apiurl +'/withdrawal/index';
    let key=wx.getStorageSync('key');
    wx.request({
      url: url,
      data:{key:key},
      header:{
        'Content-type':'application/x-www-form-urlencoded'
      },
      method:'POST',
      success:res=>{
        console.log(res);
        let cashInfo=res.data.datas.info;
        this.setData({
          cashInfo
        })
      }
    })
  },
  // 获取信息
  getDataUser() {
    let url = apiurl + '/member/index'
    let key = wx.getStorageSync('key')
    wx.request({
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      url: url,
      method: 'POST',
      data: {
        key
      },
      success: data => {
        console.log(data)
        if (data.data.code == 200) {
          let info = data.data.datas.member_info;
          // 总额计算保留两位小数
          let totalMoney = parseFloat(info.money + parseFloat(info.generation_money)).toFixed(2);
       
          this.setData({
            info,
            totalMoney
          })
          console.log('totalMoney',this.data.totalMoney)
        }else if(data.data.code == 400){
          pulibc.navigateUrl('../register/register');
        }
         else {
          pulibc.showToast(data.data.datas.error, 'none')
        }
      }

    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getCashInfo();
    this.onShow();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    if (wx.getStorageSync("key") == false) {
      wx.navigateTo({
        url: "../register/register"
      })
    }else{
      this.getDataUser()
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})